package TestExercises01;

import java.util.Scanner;

//评委打分————6个评委，去掉最高分和最低分，求剩下4个评委的平均数
public class test05 {
    public static void main(String[] args) {
        int[] scoreArr = getScores();//求各个评委给选手打的分
        System.out.print("数组中的值为：");
        for (int i = 0; i < scoreArr.length; i++) {
            System.out.print(scoreArr[i] + "  ");
        }
        System.out.println();
        int max = getMax(scoreArr);//求最大值
        System.out.println("数组的最大值为：" + max);
        int min = getMin(scoreArr);//求最小值
        System.out.println("数组的最小值为：" + min);
        int sum = getSum(scoreArr);//求总和
        int avg = (sum - max - min) / (scoreArr.length - 2);
        System.out.println("选手的最终得分为：" + avg);
    }

    //得出评委打分的数组
    public static int[] getScores() {
        int[] scores = new int[6];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < scores.length; ) {
            System.out.println("请输入评委的打分：(0~100)");
            int score = sc.nextInt();
            if (score >= 0 && score <= 100) {
                scores[i] = score;
                i++;
            } else {
                System.out.println("成绩超出了范围，继续录入，当前的i为：" + i);
            }
        }
        return scores;
    }

    //求最大值
    public static int getMax(int[] scoreArr) {
        int max = scoreArr[0];
        for (int i = 1; i < scoreArr.length; i++) {
            if (scoreArr[i] > max) {
                max = scoreArr[i];
            }
        }
        return max;
    }

    //求最小值
    public static int getMin(int[] scoreArr) {
        int min = scoreArr[0];
        for (int i = 1; i < scoreArr.length; i++) {
            if (scoreArr[i] < min) {
                min = scoreArr[i];
            }
        }
        return min;
    }

    //求总和
    public static int getSum(int[] scoreArr) {
        int sum = 0;
        for (int i = 0; i < scoreArr.length; i++) {
            sum = sum + scoreArr[i];
        }
        return sum;
    }
}
